package drone.basis.express ;

import com.googlecode.aviator.runtime.function.AbstractFunction ;
import com.googlecode.aviator.runtime.function.FunctionUtils ;
import com.googlecode.aviator.runtime.type.AviatorDouble ;
import com.googlecode.aviator.runtime.type.AviatorObject ;

import java.nio.ByteBuffer ;
import java.nio.ByteOrder ;
import java.util.Map ;

public class FuncS16 extends AbstractFunction
{

	@Override
	public AviatorObject call (
			Map < String , Object > env ,
			AviatorObject arg1 ,
			AviatorObject arg2
	)
	{
		byte u16_H = FunctionUtils.getNumberValue ( arg1 , env ).byteValue ( ) ;
		byte u16_L = FunctionUtils.getNumberValue ( arg2 , env ).byteValue ( ) ;
		ByteBuffer bb = ByteBuffer.allocate ( 2 ).order ( ByteOrder.BIG_ENDIAN ) ;
		bb.put ( u16_H ).put ( u16_L ) ;
		return new AviatorDouble ( ( double ) ( bb.getShort ( 0 ) ) ) ;
	}

	public String getName ( )
	{
		return "s16" ;
	}
}
